import { defineStore } from 'pinia'
import { ref } from "vue"
// import { login } from '@api/auth'

export const useAuthStore = defineStore(
    'auth',
    () => {
        let token = ref('')
        const setToken = (data) => {
            token.value = data
        }

        const authLogin = async () => {
            // const res = await login()
            const res = 'token'
            setToken(res)
            return res
        }

        const authLogOut = async () => {
            setToken('')
            return ''
        }

        return {
            token,
            setToken,
            authLogin,
            authLogOut
        }
    },
    // TODO: 持久化
    {
        persist: {
            storage: localStorage,
            paths: ['token'],
        },
    },
)